;
(function() {
	var role = require("./role");
	var db = require("../../core/db/index");
	var config = require("../../core/_include/config");
	var AdminCon = require("../../core/admin/_con");
	var DotnarMessageCon = require("../../core/dotnar_message/_con");
	var ResponObj = require("../_include/responObj");
	module.exports = {
		prefix: "/message",
		get: {
			"/byId": function() {
				var query = this.query;
				var message_id = query.message_id;
				if (!message_id) {
					throwCusError("参数错误")
				}
				var dotnar_message = DotnarMessageCon.get(message_id);
				if (!dotnar_message) {
					throwCusError("找不到指定留言")
				}
				this.body = ResponObj("json", dotnar_message);
			},
			"/list": function() {
				var query = this.query;
				var dotnar_message_list = DotnarMessageCon.getAll(query.num, query.page);
				this.body = ResponObj("json", dotnar_message_list);
			},
		},
		post: {
			"/add_message": function() {
				var message_info = this.request.body;
				var message = new DotnarMessageCon(message_info);
				this.body = ResponObj("json", message);
			},
		},
		put: {
			"/reply_message": function() {
				var dotnar_message = this.request.body;
				var message_id = dotnar_message.message_id;
				var reply_content = dotnar_message.content;
				if (!(message_id && reply_content)) {
					throwCusError("参数错误");
				}
				var admin = role.getAdmin(this);
				admin.replyMessage(message_id, reply_content);
				this.body = ResponObj("json", DotnarMessageCon.get(message_id));
			}
		},
		"delete": {
			"/remove_message": function() {
				var body = this.request.body;
				var message_id = body.message_id;
				if (!message_id) {
					throwCusError("参数错误")
				}
				var admin = role.getAdmin(this);
				admin.removeMessage(message_id);
				return module.exports.get["/list"].apply(this, arguments);
			},
		}
	}
}());